#include <iostream>
#include <string>
using namespace std;

class Solution {
public:
    bool isMatch(string s, string p) {
        bool dp[30][50];
        int iSize = s.size();
        int jSize = p.size();
        dp[0][0] = true;
        for(int i = 1; i <= iSize; i++){
            dp[i][0] = false;
        }
        for(int j = 1; j <= jSize; j++){
            if(p[j - 1] != '*') dp[0][j] = false;
            else if(j >= 2 && dp[0][j - 2]) dp[0][j] = true;
            else if(j == 2) dp[0][j] = true;
            else dp[0][j] = false;
        }
        for(int j = 1; j <= jSize; j++){
            for(int i = 1; i <= iSize; i++){
                if(p[j - 1] == s[i - 1] || p[j - 1] == '.') dp[i][j] = dp[i - 1][j - 1];
                else if(p[j - 1] == '*'){
                    if(i == 1 && j == 7)
                        int aaa = 4;
                    if(dp[i][j - 1] == true) dp[i][j] = true;
                    else if(dp[i - 1][j] == true &&((i >=2 && p[j - 2] == s[i - 1]) || p[j - 2] == '.')) dp[i][j] = true;
                    else if(dp[i][j - 2]) dp[i][j] = true;
                    else dp[i][j] = false;
                }
                else dp[i][j] = false;
            }
        }
        // return p[1] == '.';
        return dp[iSize][jSize];
    }
};
int main() {
    Solution solve;
    string a = "mississippi";
    string b = "mis*is*p*.";

    bool res = solve.isMatch(a, b);
    std::cout << "Hello, World!" << std::endl;
    return 0;
}
